const {
  override,
  fixBabelImports,
  addLessLoader,
  adjustStyleLoaders,
  addBabelPlugins,
} = require("customize-cra");

const addDevServerConfig = () => (config) => {
  if (config.devServer) {
    config.devServer.allowedHosts = config.devServer.allowedHosts || [];
    config.devServer.allowedHosts.push("localhost");
  }
  return config;
};

module.exports = override(
  fixBabelImports("import", {
    libraryName: "antd",
    libraryDirectory: "es",
    style: true,
  }),
  addLessLoader({
    lessOptions: {
      javascriptEnabled: true,
      modifyVars: {
        "@primary-color": "#1DA57A",
      },
    },
  }),
  adjustStyleLoaders(({ use: [, , postcss] }) => {
    const postcssOptions = postcss.options;
    postcss.options = { postcssOptions };
  }),
  addBabelPlugins(["@babel/plugin-proposal-decorators", { legacy: true }]),
  addDevServerConfig()
);
